package com.集合.Collection___.Set_.LinkedHashSet__;

import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Objects;

@SuppressWarnings("all")
public class LinkedHashSetExercise01 {
    public static void main(String[] args) {
        LinkedHashSet lhs = new LinkedHashSet();
        lhs.add(new Car("奥拓",1000));
        lhs.add(new Car("奥迪",300000));
        lhs.add(new Car("法拉利",10000000));
        lhs.add(new Car("奥迪",300000));
        lhs.add(new Car("保时捷",70000000));
        lhs.add(new Car("奥迪",300000));
        System.out.println(lhs);
        lhs.add(new A("哈哈"));
        lhs.add(new A("哈哈"));
        lhs.add(new A("哈哈"));
        lhs.add(new A("哈哈"));
        System.out.println(lhs);

    }
}
class Car{
    private String name;
    private int price;
    public Car(String name, int price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        return  name+ ' '+ price;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        Car car = (Car) o;
        return price == car.price && Objects.equals(name, car.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, price);
    }
}

class A{
    private String name;

    public A(String name) {
        this.name = name;
    }



    @Override
    public int hashCode() {
        return 16;
    }

    @Override
    public String toString() {
        return name;
    }
}